package com.hqully.labmanage.controller;

import com.hqully.labmanage.domain.entity.DeviceFault;
import com.hqully.labmanage.domain.dto.DeviceFaultDTO;
import com.hqully.labmanage.service.DeviceFaultService;
import com.hqully.labmanage.utils.ResultVOUtil;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备故障数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"设备故障数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/deviceFault")
public class DeviceFaultController extends BaseController {

    @Resource
    private DeviceFaultService deviceFaultService;

    @ApiOperation(value = "分页条件查询设备故障列表")
    @GetMapping("/page-deviceFaults")
    public ResultVO<PageInfo<DeviceFaultDTO>> pageDeviceFaults(PageDTO page, DeviceFaultDTO deviceFaultDTO) {
        PageInfo<DeviceFaultDTO> deviceFaultPage = deviceFaultService.pageDeviceFaults(page, deviceFaultDTO);
        return ResultVOUtil.success(deviceFaultPage);
    }

    @ApiOperation(value = "条件查询设备故障列表")
    @GetMapping("/list-deviceFaults")
    public ResultVO<List<DeviceFaultDTO>> listDeviceFaults(DeviceFaultDTO deviceFaultDTO) {
        List<DeviceFaultDTO> deviceFaultList = deviceFaultService.listDeviceFaults(deviceFaultDTO);
        return ResultVOUtil.success(deviceFaultList);
    }

    @ApiOperation(value = "添加设备故障")
    @PostMapping("/add-deviceFault")
    public ResultVO<DeviceFaultDTO> addDeviceFault(@Validated @RequestBody DeviceFaultDTO deviceFaultDTO) {
        deviceFaultService.addDeviceFault(deviceFaultDTO);
        return ResultVOUtil.success("添加设备故障成功");
    }

    @ApiOperation(value = "更新设备故障")
    @PostMapping("/update-deviceFault")
    public ResultVO<DeviceFaultDTO> updateDeviceFault(@Validated @RequestBody DeviceFaultDTO deviceFaultDTO) {
        deviceFaultService.updateDeviceFault(deviceFaultDTO);
        return ResultVOUtil.success("更新设备故障成功");
    }

    @ApiOperation(value = "删除设备故障")
    @DeleteMapping("/delete-deviceFault/{id}")
    public ResultVO<DeviceFaultDTO> deleteDeviceFault(@PathVariable("id") Integer id) {
        deviceFaultService.deleteDeviceFaultById(id);
        return ResultVOUtil.success("删除设备故障成功");
    }

}

